var haystack = 'mississippi';
var needlr = 'issip';

var strStr = function (haystack, needle) {
    if (haystack.length == 0) {
        return ''
    } else if(haystack.length < needle.length) {
        return -1
    }else {
        var harr = [], narr = [];
        var flag = 0, sum = 0, flag1 = 0;
        for (var i = 0; i < haystack.length; i++) {
            harr[i] = haystack.charAt(i);
            if (i < needle.length) {
                narr[i] = needle.charAt(i)
            }
        }
        harr.forEach((item, index) => {
            if(item == narr[flag] && (index == sum+1 || flag == 0)) {
                console.log('12',index)
                if(flag == 0) {
                    flag1 = index
                }
                sum = index
                flag ++
            }
        })
        if (flag == narr.length) {
            return flag1
        } else {
            return -1
        }
    }
}

console.log(strStr(haystack, needlr))